package com.shujia.day16;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/*
    把java/src/com/shujia/day16/a4.txt内容复制到java/src/com/shujia/day16/b1.txt中
    数据源：java/src/com/shujia/day16/a4.txt
        字符输入流：
            Reader:
                - InputStreamReader
    目的地：java/src/com/shujia/day16/b1.txt
        字符输出流：
            Writer:
                - OutputStreamWriter

 */
public class CopyFileTest3 {
    public static void main(String[] args) throws Exception {
        // 创建字符输入流对象
        InputStreamReader isr = new InputStreamReader(new FileInputStream("java/src/com/shujia/day16/a4.txt"));
        //创建字符输出流对象
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("java/src/com/shujia/day16/b2.txt"));

        //一次读写一个字符
//        int i = 0;
//        while ((i = isr.read()) != -1) {
//            osw.write(i);
//            osw.flush();
//        }

        //一次读写一个字符数组
        char[] chars = new char[1024];
        int length = 0;
        while ((length=isr.read(chars))!=-1){
            osw.write(chars,0,length);
            osw.flush();
        }


        //释放资源
        osw.close();
        isr.close();
    }
}
